package dbConexao;


 import java.sql.Connection;  
 import java.sql.DriverManager;  
 import java.sql.ResultSet;  
import java.sql.SQLException; 

import com.mysql.jdbc.Statement;

// fabrica de conexoes
 public class ConnectionFactory {  
     private static final String url = "jdbc:mysql://150.165.93.217:23456/DB_TEST";  
     private static final String driver = "com.mysql.jdbc.Driver";  
     private static final String usuario = "root";  
     private static final String senha = "sqlR00t";  
   
        
     public static Connection getConnection() throws SQLException {  
         try {  
             System.out.println("Conectando ao banco");  
             Class.forName(driver);  
             return DriverManager.getConnection(url, usuario, senha);  
         } catch (ClassNotFoundException e) {  
             throw new SQLException(e.getMessage());  
         }  
     }  
     
     
     // teste com o banco de dados
     public static void main(String[] args) throws SQLException {
		System.out.println("teste");
		
		Connection con = ConnectionFactory.getConnection();
		Statement stm = (Statement) con.createStatement();
		ResultSet rs = stm.executeQuery("SELECT nome, telefone FROM pessoa");
		while (rs.next()) {
			String nome = rs.getString("nome");
			String telefone = rs.getString("telefone");
			System.out.println("Nome: " + nome + "\tTelefone: " + telefone);
		}
	}
     
     
     
   
 }  